// MarketInternalGoodsCodeApi.ts
import fetcher from "../apis/Fetcher";

// 请求参数类型定义
export interface AddMarketInternalGoodsCodeRequest {
    code: string;
    goodsId: number;
}

export interface UpdateMarketInternalGoodsCodeRequest {
    code: string;
}

// 响应类型定义
export interface MarketInternalGoodsCodeResponse {
    id: number;
    code: string;
    goodsId: number;
    name: string;
    barcode: string;
}

/**
 * 获取指定卖场下的所有内部商品码
 * @param marketId 卖场ID
 */
export function getAllInternalGoodsCodes(
    marketId: number
) {
    return fetcher.get<MarketInternalGoodsCodeResponse[]>(`markets/${marketId}/internalGoodsCodes`);
}

/**
 * 获取指定ID的内部商品码详情
 * @param marketId 卖场ID
 * @param id 内部码ID
 */
export function getInternalGoodsCodeById(
    marketId: number,
    id: number
) {
    return fetcher.get<MarketInternalGoodsCodeResponse>(`markets/${marketId}/internalGoodsCodes/${id}`);
}

/**
 * 添加新的内部商品码
 * @param marketId 卖场ID
 * @param request 添加请求参数
 */
export function addInternalGoodsCode(
    marketId: number,
    request: AddMarketInternalGoodsCodeRequest
) {
    return fetcher.post<MarketInternalGoodsCodeResponse>(`markets/${marketId}/internalGoodsCodes`, {}, request);
}

/**
 * 更新内部商品码
 * @param marketId 卖场ID
 * @param id 内部码ID
 * @param request 更新请求参数
 */
export function updateInternalGoodsCode(
    marketId: number,
    id: number,
    request: UpdateMarketInternalGoodsCodeRequest
) {
    return fetcher.put<MarketInternalGoodsCodeResponse>(`markets/${marketId}/internalGoodsCodes/${id}`, {}, request);
}

/**
 * 删除内部商品码
 * @param marketId 卖场ID
 * @param id 内部码ID
 */
export function deleteInternalGoodsCode(
    marketId: number,
    id: number
) {
    return fetcher.delete(`markets/${marketId}/internalGoodsCodes/${id}`);
}